﻿package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import org.drawlineapi.tools.AbsLine;
	import org.drawlineapi.tools.DashedLine;
	import org.drawlineapi.tools.IndicativeLine;
	import org.drawlineapi.tools.SimpleLine;
	
	/**
	 * ...
	 * @author Ricardo Teixeira
	 */
	public class Draw extends Sprite {
		
		private var line:AbsLine;
		private var w:Number;
		private var h:Number;
		
		public function Draw(w:Number, h:Number):void {
			this.w = w;
			this.h = h;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			this.graphics.beginFill (0xCCCCCC);
			this.graphics.drawRect (0, 0, w, h);
			
			this.addEventListener (MouseEvent.MOUSE_DOWN, onDown);
			
		}
		
		private function onDown(e:MouseEvent):void {
			this.addEventListener (MouseEvent.MOUSE_MOVE, onMove);
			this.addEventListener (MouseEvent.MOUSE_UP, onUp);
			
			var from:Point = new Point (this.x + this.mouseX, this.y + this.mouseY);
			var to:Point = new Point (this.x + this.mouseX, this.y + this.mouseY);
			
			this.line = new IndicativeLine (from, to);
			
			//IndicativeLine (this.line).changeStartIcon ( new AgregationIcon () );
			//IndicativeLine (this.line).changeEndIcon ( new AgregationIcon () );
			
			IndicativeLine (this.line).desableStartIcon ();
			//IndicativeLine (this.line).desableEndIcon ();
			
			this.addChild (this.line);
		}
		
		private function onUp(e:MouseEvent):void {
			this.removeEventListener (MouseEvent.MOUSE_MOVE, onMove);
			this.removeEventListener (MouseEvent.MOUSE_UP, onUp);
		}
		
		private function onMove(e:MouseEvent):void {
			var to:Point = new Point (this.x + this.mouseX, this.y + this.mouseY);
			this.line.to = to;
		}
		
	}
	
}